package demo;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Game {
    private static final String[] suits = {"♥","♣","♦","♠"};

    //买52张牌
    public  List<Poker> buyPoker(){

        //1. 如果拿接口对象 来接收对象：好处是 可以发生向上转型。
        //拿接口来接收，可以做到接收不同的对象，只要实现了这个接口的都可以。
        //list只能调用父类自己的方法
        List<Poker> pokers = new ArrayList<>();

        //2.当前类的都可以调用
        ArrayList<Poker> poker1 = new ArrayList<>();

        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <= 13; j++) {
                String suit = suits[i];
                int rank = j;
                Poker poker = new Poker(suit,rank);
                pokers.add(poker);
            }
        }
        return pokers;
    }
    public void shuffle(List<Poker> pokers){
        for (int i = pokers.size()-1; i > 0; i--) {
            Random random = new Random();
            int index = random.nextInt(i); //[0,i)
            swap(pokers,i,index);
        }
    }
    public void swap(List<Poker> pokers,int i,int j){
        Poker tmp = pokers.get(i);
        pokers.set(i,pokers.get(j));
        pokers.set(j,tmp);
    }
    public List<List<Poker>> game(List<Poker> pokers){
        List<List<Poker>> hand = new ArrayList<>();

        List<Poker> hand1 = new ArrayList<>();
        List<Poker> hand2 = new ArrayList<>();
        List<Poker> hand3 = new ArrayList<>();

        hand.add(hand1);
        hand.add(hand2);
        hand.add(hand3);

        //外层循环： 轮数
        for (int i = 0; i < 5; i++) {
            //人数
            for (int j = 0; j < 3; j++) {
                //删除哪个下标的值，会把哪个下标的值，进行返回
                Poker removePoker = pokers.remove(0);
                hand.get(j).add(removePoker);
            }
        }
        return hand;
    }

}
